<?php
// +----------------------------------------------------------------------
// | CoreThink [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.corethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ijry <ijry@qq.com> <http://www.corethink.cn>
// +----------------------------------------------------------------------
namespace Home\Controller;
use Think\Page;
/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {
    //系统首页
    public function index(){
        if(C('WEB_SITE_HOME_PAGE') !== 'Index/index'){
            $this->redirect(C('WEB_SITE_HOME_PAGE'));
        }
        $this->assign('meta_title', '首页');
        $this->assign('meta_keywords', C('WEB_SITE_KEYWORD'));
        $this->assign('meta_description', C('WEB_SITE_DESCRIPTION'));
        $this->display();
    }

    //搜索
    public function search(){
        if($_GET['key']){
            $key  = (string)I('key');
            $list = D('Document')->page(!empty($_GET["p"])?$_GET["p"]:1, 10)->lists($category = null, $field = true, $order = "`create_time` desc", $status = 1, $uid = false, $pos = false , $key);
            $count = D('Document')->listCount($category, $status = 1, $uid = false, $pos = false, $key);
            $Page = new Page($count,10);
            $show = $Page->show();
            $this->assign('list', $list);
            $this->assign('page',$show);
            $this->assign('meta_title', '搜索');
            $this->assign('meta_keywords', C('WEB_SITE_KEYWORD'));
            $this->assign('meta_description', C('WEB_SITE_DESCRIPTION'));
        }else{
            $this->error("请您输入关键字后搜索");
        }
        $this->display();
    }
}
